﻿using DemoMVVM.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;

namespace DemoMVVM
{
	public class MainWindowViewModel : ViewModelBase
	{
		#region 属性及构造函数

		private double leftNumber;

		public double LeftNumber
		{
			get { return leftNumber; }
			set { SetProperty(ref leftNumber, value); }
		}

		private double rightNumber;

		public double RightNumber
		{
			get { return rightNumber; }
			set { SetProperty(ref rightNumber, value); }
		}

		private double resultNumber;

		public double ResultNumber
		{
			get { return resultNumber; }
			set { SetProperty(ref resultNumber, value); }
		}


		public MainWindowViewModel()
		{

		}

		#endregion

		#region 命令

		private DelegateCommand operationCommand;

		public DelegateCommand OperationCommand
		{
			get
			{

				if (operationCommand == null)
				{
					operationCommand = new DelegateCommand(Operate);
				}
				return operationCommand;
			}
		}

		private void Operate(object obj)
		{
			if (obj == null)
			{
				return;
			}
			var type = obj.ToString();
			switch (type)
			{
				case "+":
					this.ResultNumber = this.LeftNumber + this.RightNumber;
					break;
				case "-":
					this.ResultNumber = this.LeftNumber - this.RightNumber;
					break;
				case "*":
					this.ResultNumber = this.LeftNumber * this.RightNumber;
					break;
				case "/":
					if (this.RightNumber == 0)
					{
						this.ResultNumber = 0;
					}
					else
					{
						this.ResultNumber = this.LeftNumber / this.RightNumber;
					}
					break;
			}
		}


		#endregion

	}
}
